﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;

namespace ImageResizer
{
    class Program
    {
        static void PrintHelp()
        {
            string help = "ImageResizer.exe dir parrten newwidth=?";
            Console.WriteLine(help);
        }

        public static void Main(string[] args)
        {
            if (args.Length < 3)
            {
                PrintHelp();
                return;
            }
            try
            {

                string[] files = System.IO.Directory.GetFiles(args[0], args[1], System.IO.SearchOption.TopDirectoryOnly);

                if (files.Length == 0)
                {
                    Console.WriteLine("没有找到任何文件，搜索条件:" + args[0] + args[1]);
                    return;
                }
                Console.WriteLine("共找到图片:" + files.Length);
                foreach (string file in files)
                {
                    bool ret = ImageToolKit.Net.ImageToolKitNative.ImageResize(file, file + ".jpg", int.Parse(args[2]));
                    if (ret == true)
                    {
                        File.Delete(file);
                        File.Move(file + ".jpg", file);
                        Console.WriteLine("已成功:" + file);
                    }
                    else
                    {
                        Console.WriteLine("处理过程中止，因为无法处理图片:" + file);
                        return;
                    }
                }

                Console.WriteLine("共处理图片:" + files.Length);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}
